package cn.yunhe.control;

import cn.yunhe.entity.Blank;
import cn.yunhe.entity.Topic;
import cn.yunhe.server.TopicServer;
import cn.yunhe.util.JasonUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/GetTopicInfoByAjaxServlet")
public class GetTopicInfoByAjaxServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int bId = Integer.parseInt(request.getParameter("bId"));
        String title = request.getParameter("title");
        //新建板块对象和主贴对象
        Blank blank = new Blank();
        blank.setbId(bId);
        Topic topic = new Topic();
        topic.setTitle(title);
        //新建server对象
        TopicServer topicServer = new TopicServer();
        List<Topic> list = topicServer.AccurateSelectTopicByTopic(topic, blank); //获取主贴对象
        if (list != null && list.size() > 0) {
            JasonUtil.getJson(response,list); //将list内容格式化成Jason格式
        }else {
            JasonUtil.getJson(response,"该主贴为空"); //将list内容格式化成Jason格式
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
